<?php
if (!$alimama_deluxe->legency_mode && (!$alimama_deluxe->have_user || !$alimama_deluxe->have_this_site)) {
	wp_die("Alimama Deluxe 插件尚未正确与 Alimama 帐号关联，请到 <a href=\"admin.php?page=alimama-deluxe/alimama-deluxe-index.php\">Alimama Deluxe 首页</a>完成关联。");
}
	require_once(dirname(__FILE__) . "/alimama-deluxe-functions.php");
	$action = strtolower(trim($_GET['a']));
	if (empty($action)) $action = 'manage';
	if (!in_array($action,array('manage','add','edit','delete','disable','enable'))) $action = 'manage';
	
	if ($action == 'enable' || $action == 'disable') {
		$id = intval($_GET['ad_id']);
		if (empty($id)) wp_die('Hacking Attamp!');
		$r = $alimama_deluxe->ad_update_item($id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,$action);
		$action = 'manage';
	} elseif ($action == 'delete') {
		$id = intval($_GET['ad_id']);
		if (empty($id)) wp_die('Hacking Attamp!');
		$alimama_deluxe->ad_remove_item($id);
		$action = 'manage';
	} elseif ($action == 'add' || $action == 'edit') {
			class ad_strategy_recode {
				var $ID = 0;
				var $ad_name = '';
				var $ad_code = '';
				var $ad_type = 'autocontent';
				var $ad_strategy = '1';
				var $ad_repeat_limit = 0;
				var $ad_article_pos = 1;
				var $ad_page_pos = 3;
				var $ad_position = 'bottom';
				var $ad_manualformat = '%code%';
				var $ad_enable = 'enable';
				var $ad_alimama_pid = '';
				var $ad_style;
				var $ad_jscode;
			}
			$adv= new ad_strategy_recode;
			$adv->ad_code = sprintf("strategy%d",rand(1000,9999));
			$adv->ad_style = array('sys1','');
			if ($action == 'edit') {
				$id = intval($_GET['ad_id']);
				$adv=$wpdb->get_row("SELECT * FROM $alimama_deluxe->ad_table WHERE ID=$id");
				$adv->ad_style = unserialize($adv->ad_style);
				$adv->ad_style[1] = base64_decode($adv->ad_style[1]);
				$adv->ad_jscode = base64_decode($adv->ad_jscode);
				$adv->ad_jscode = stripslashes($adv->ad_jscode);
				//var_dump($adv->ad_jscode);
				if (!$adv) {
					wp_die("Hacking Attamp!");
				}
			}
	}

	if (isset($_POST)) {
		if (isset($_POST['alimama_deluxe_add_item'])) {
			// add new strategy
			//$_ad_strategy = $_POST['ad_strategy'];
			//if ($_ad_strategy == 'custom') $_ad_strategy = $_POST['ad_strategy_custom'];
			//var_dump($_POST);
			if ($alimama_deluxe->ad_add_item($_POST['ad_name'],$_POST['ad_code'],$_POST['ad_type'],1,1,$_POST['ad_article_pos'],$_POST['ad_page_pos'],$_POST['ad_position'],$_POST['ad_manualformat'],$_POST['ad_enable'],$_POST['ad_alimama_pid'],$_POST['alimama_deluxe_color_scheme_name'],$_POST['alimama_deluxe_color_scheme_detail'],$_POST['ad_alimama_deluxe_js_code'])) {
				echo '<script type="text/javascript">location.href="admin.php?page=alimama-deluxe/alimama-deluxe-strategy-manage.php&success=add";</script>';
				exit;
			} else {
				foreach ($alimama_deluxe->errors as $e) {
					$error_msg .= (!empty($error_msg)?'<br />':"") . $e[2];
				}
			}
		} elseif (isset($_POST['alimama_deluxe_edit_item'])) {
			// edit strategy
			//$_ad_strategy = $_POST['ad_strategy'];
			//if ($_ad_strategy == 'custom') $_ad_strategy = $_POST['ad_strategy_custom'];
			if ($alimama_deluxe->ad_update_item($_POST['ad_ID'],$_POST['ad_name'],$_POST['ad_code'],$_POST['ad_type'],1,1,$_POST['ad_article_pos'],$_POST['ad_page_pos'],$_POST['ad_position'],$_POST['ad_manualformat'],$_POST['ad_enable'],$_POST['ad_alimama_pid'],$_POST['alimama_deluxe_color_scheme_name'],$_POST['alimama_deluxe_color_scheme_detail'],$_POST['ad_alimama_deluxe_js_code'])) {
				echo '<script type="text/javascript">location.href="admin.php?page=alimama-deluxe/alimama-deluxe-strategy-manage.php&success=edit";</script>';
				exit;
			} else {
				//echo error
				foreach ($alimama_deluxe->errors as $e) {
					$error_msg .= (!empty($error_msg)?'<br />':"") . $e[2];
				}
			}
		}
		if (!empty($error_msg)) {
			$adv->ID = $_POST['ad_ID'];
			$adv->ad_name = $_POST['ad_name'];
			$adv->ad_code = $_POST['ad_code'];
			$adv->ad_type = $_POST['ad_type'];
			$adv->ad_strategy = $_ad_strategy;
			$adv->ad_repeat_limit = $_POST['ad_repeat_limit'];
			$adv->ad_article_pos = $_POST['ad_article_pos'];
			$adv->ad_page_pos = $_POST['ad_page_pos'];
			$adv->ad_position = $_POST['ad_position'];
			$adv->ad_manualformat = $_POST['ad_manualformat'];
			$adv->ad_enable = $_POST['ad_enable'];
			$adv->ad_alimama_pid = $_POST['ad_alimama_pid'];
			$adv->ad_style = array($_POST['alimama_deluxe_color_scheme_name'],$_POST['alimama_deluxe_color_scheme_detail']);
			$adv->ad_jscode ='';//should be generated automatically.
			if ($alimama_deluxe->legency_mode) $adv->ad_jscode = $_POST['ad_alimama_deluxe_js_code'];
		}
	}
?>
<?php 
	if (!empty($_GET['success'])) {
		switch ($_GET['success']) {
			case 'add':
				$message = '新广告策略添加成功！';
				break;
			case 'edit':
				$message = '广告策略更新成功！';
				break;
		}
		?>
		<div style="background-color: rgb(207, 235, 247);" id="message" class="updated fade"><p><strong><?php echo $message; ?></strong></p></div>
		<?php
	} elseif (!empty($error_msg)) {
		?>
		<div style="background-color: #FFC0CB;" id="message" class="updated fade"><p><strong><?php echo $error_msg; ?></strong></p></div>
		<?php
	}
?>
<div class="wrap">
<?php
	switch($action) {
		case 'add':
		case 'edit':
			?>
			<script type="text/javascript">
				function onChange_ad_strategy() {
					if (jQuery('#ad_strategy')[0].value == 'custom') {
						jQuery('#ad_strategy_custom_div').show();
					} else {
						jQuery('#ad_strategy_custom_div').hide();
					}
				}
				function onChange_ad_position() {
					if (jQuery('#ad_position')[0].value == 'manual') {
						jQuery('#ad_detail_manualformat').show();
					} else {
						jQuery('#ad_detail_manualformat').hide();
					}
				}
				function onChange_ad_type() {
					//jQuery('#ad_detail_strategy').hide();
					//jQuery('#ad_detail_repeat_limit').hide();
					jQuery('#auto_article_pos').hide();
					jQuery('#ad_detail_position').hide();
					jQuery('#ad_detail_manualformat').hide();
					jQuery('#ad_detail_settings').hide();
					switch(jQuery('#ad_type')[0].value) {
						case 'autocontent':
							//jQuery('#ad_detail_strategy').show();
							//jQuery('#ad_detail_repeat_limit').show();
							jQuery('#ad_detail_position').show();
							jQuery('#auto_article_pos').show();
							jQuery('#ad_detail_settings').show();
							var ps_opts = jQuery('#ad_position')[0].options;
							for (i=0;i<ps_opts.length;i++) {
								switch(ps_opts[i].value) {
									case 'top':
									case 'bottom':
									case 'secondpara':
									case 'floatleft':
									case 'floatright':
										ps_opts[i].disabled = false;
										break;
									case 'manualfloat':
									case 'manual':
										ps_opts[i].disabled = true;
										break;
								}
							}
							if (jQuery('#ad_position')[0].value=='manualfloat' || jQuery('#ad_position')[0].value == 'manual') jQuery('#ad_position')[0].value = 'bottom';
							//onChange_ad_strategy();
							onChange_ad_position();
							break;
						case 'manualcontent':
							//jQuery('#ad_detail_repeat_limit').show();
							jQuery('#ad_detail_position').show();
							jQuery('#ad_detail_settings').show();
							var ps_opts = jQuery('#ad_position')[0].options;
							for (i=0;i<ps_opts.length;i++) {
								switch(ps_opts[i].value) {
									case 'manualfloat':
									case 'manual':
									case 'floatleft':
									case 'floatright':
										ps_opts[i].disabled = false;
										break;
									case 'top':
									case 'bottom':
									case 'secondpara':
										ps_opts[i].disabled = true;
										break;
								}
							}
							if (jQuery('#ad_position')[0].value=='top' || jQuery('#ad_position')[0].value == 'bottom' || jQuery('#ad_position')[0].value == 'secondpara') jQuery('#ad_position')[0].value = 'manualfloat';
							//onChange_ad_strategy();
							onChange_ad_position();
							break;
						case 'widget':
							break;
						case 'manualpage':
							jQuery('#ad_detail_manualformat').show();
							jQuery('#ad_detail_settings').show();
							break;
					}
					ad_show_pagepos();
				}
				//addLoadEvent(onChange_ad_strategy);
				addLoadEvent(onChange_ad_position);
				addLoadEvent(onChange_ad_type);
			</script>
			<h2><?php if ($action == 'add') {?>新建广告策略<a class="helplink" href="http://alimama-deluxe.wordpresscn.com/create-ad-strategy/" target="_blank">[?]</a><?php }else{ ?>编辑广告策略<a class="helplink" href="http://alimama-deluxe.wordpresscn.com/edit-ad-strategy/" target="_blank">[?]</a><?php } ?></h2>
			<form method="post">
			<table width="98%">
			<?php if (!$alimama_deluxe->legency_mode) { ?>
				<tr>
					<th width="20%" valign="top">关联 Alimama 广告位</th>
					<td><?php
						$r = $alimama_deluxe->api->zone_info();
						$js_ads = "";
						$opts = "";
						if ($r && $alimama_deluxe->api->success) {
							$zs = &$alimama_deluxe->api->result;
							if (isset($r['adzoneid'])) {
								$temp = array();
								$temp[0] = $zs;
								$zs = $temp;
							}
							foreach ($zs as $z) {
								if ($z['siteid'] != $alimama_deluxe->api->site_id) continue;
								$js_ads .= "{pid:'mm_{$z["memberid"]}_{$z["siteid"]}_{$z["adzoneid"]}',adzoneid:'{$z["adzoneid"]}',name:'{$z["name"]}',format:'{$z["format"]}',transtype:'{$z["transtype"]}',sizecode:'{$z["sizecode"]}',adzonesize:'{$z["adzonesize"]}',weekprice:'{$z["weekprice"]}',createtime:'{$z["createtime"]}',updatetime:'{$z["updatetime"]}',status:'{$z["status"]}',memberid:'{$z["memberid"]}',siteid:'{$z["siteid"]}',keywords:'{$z["keywords"]}',adzonecatids:'{$z["adzonecatids"]}',needauditing:'{$z["needauditing"]}',zonedesc:'{$z["zonedesc"]}',homepage:'{$z["homepage"]}',canselltime:'{$z["canselltime"]}'},";
								$opts .= "<option value=\"mm_{$z['memberid']}_{$z['siteid']}_{$z['adzoneid']}\"";
								if ("mm_{$z['memberid']}_{$z['siteid']}_{$z['adzoneid']}" == $adv->ad_alimama_pid) $opts .= " selected";
								switch ($z['status']) {
									case 'N': $opts .=">{$z['name']}(审核中)";break;
									case 'A': $opts .=">{$z['name']}(上架)";break;
									case 'O': $opts .=" disabled >{$z['name']}(下架)";break;
									case 'R': $opts .=" disabled >{$z['name']}(审核失败)";break;
									case 'D': $opts .=" disabled >{$z['name']}(删除)";break;
								}
								$opts .="[{$z['adzonesize']}]</option>";
							}
							if (substr($js_ads,-1,1) == ',') $js_ads = substr($js_ads,0,-1);
							$js_ads = '<script type="text/javascript">var adzones = [' . $js_ads . '];</script>';
						}
						if (empty($opts)) {
							echo "当前没有任何可用的 Alimama 广告位。请点击<a href=\"admin.php?page=alimama-deluxe/alimama-deluxe-aliad.php&a=add\">此处</a>添加一些。<input type=\"hidden\" name=\"ad_alimama_pid\" value=\"\" />";
						} else {
							echo $js_ads;
							?><select id="ad_alimama_pid" name="ad_alimama_pid" size="4" onchange="change_alimama_ad_show();"><?php echo $opts;?>
							<option value="-" disabled>-----------------</option>
							<option onclick="this.selected=false;location.href='admin.php?page=alimama-deluxe/alimama-deluxe-aliad.php&a=add';" style="font-weight:bold" value="-">添加 Alimama 广告位</option>
							</select><?php
						}
					?>
					</td>
				</tr>
				<?php } ?>
				<tr>
					<th>名称</th>
					<td><input type="text" name="ad_name" value="<?php echo $adv->ad_name;?>" /> <span style="color:#666666;">广告策略的名称，用于区别不同广告策略。</span></td>
				</tr>
				<tr>
					<th>代码</th>
					<td><input type="text" name="ad_code" value="<?php echo $adv->ad_code;?>" /> <span style="color:#666666;">手工调用显示广告时所使用的代码。</span></td>
				</tr>
				<tr>
					<th>广告类型</th>
					<td><select id="ad_type" name="ad_type" onchange="onChange_ad_type();">
							<option value="autocontent"<?php if ($adv->ad_type=='autocontent') echo " selected";?>>自动插入文章正文</option>
							<option value="manualcontent"<?php if ($adv->ad_type=='manualcontent') echo " selected";?>>手动插入文章正文</option>
							<?php if ( count( $wp_registered_sidebars ) >= 1 ) { ?><option value="widget"<?php if ($adv->ad_type=='widget') echo " selected";?>>侧边栏 Widget</option><?php }	?>
							<option value="manualpage"<?php if ($adv->ad_type=='manualpage') echo " selected";?>>手动插入模板</option>
						</select>
					</td>
				</tr>
				<tr id="ad_detail_settings">
					<th valign="top">&nbsp;</th>
					<td style="border-left: medium double #cccccc;padding-left: 10px;">
						<h3>详细设置</h3>
						<table>
<?php /*						
						<tr id="ad_detail_strategy" style="display:none">
							<th valign="top">广告显示频率</th>
							<td><select id="ad_strategy" name="ad_strategy" onchange='onChange_ad_strategy()'>
								<option value="1"<?php if ($adv->ad_strategy==1) echo " selected";?>>每篇文章均显示</option>
								<option value="2"<?php if ($adv->ad_strategy==2) echo " selected";?>>每两篇文章显示一次</option>
								<option value="3"<?php if ($adv->ad_strategy==3) echo " selected";?>>每三篇文章显示一次</option>
								<option style="display:none;" value="2.5"<?php if ($adv->ad_strategy==2.5) echo " selected";?>>每五篇文章显示两次</option>
								<option value="custom"<?php if ($adv->ad_strategy!=1&&$adv->ad_strategy!=2&&$adv->ad_strategy!=3&&$adv->ad_strategy!=2.5) echo " selected";?>>自定义频率</option>
								</select>
								<span id="ad_strategy_custom_div" style="display:none">
									&nbsp;&nbsp;&nbsp;请输入频率数值：<input type="text" name="ad_strategy_custom" value="<?php echo $adv->ad_strategy;?>" size="3" maxlength="3" />
								</span>
								<div><strong>注：</strong>本设置仅对同一页面内显示多篇文章有效</div>
							</td>
						</tr>
						<tr id="ad_detail_repeat_limit" style="display:none">
							<th valign="top">同一广告显示次数限制</th>
							<td>
								同一页面内至多显示 <input type="text" name="ad_repeat_limit" value="<?php echo $adv->ad_repeat_limit;?>" size="3" maxlength="3" /> 次
								<div><strong>注：</strong>本设置仅对同一页面内显示多篇文章有效，写入 0 为不限制。。</div>
							</td>
						</tr>
*/ ?>
						<tr id="ad_detail_position">
							<th>广告显示位置</th>
							<td><span id="auto_article_pos">同页面内
								<script type="text/javascript">
									function ad_apos_add() {
										var n = parseInt(prompt('请输入具体为第几篇','1'));
										if (isNaN(n)) {
											alert('你指定的并不是有效整数，请重新输入');
											return ad_apos_add();
										} else {
											opts=jQuery('#ad_article_pos').get(0).options;
											for (i=0;i<opts.length;i++) {
												if (n == opts[i].value) {
													jQuery('#ad_article_pos').get(0).value = n;
													return true;
												}
											}
											// add a new option
											jQuery('#ad_article_pos_lastopt').before('<option value="'+n+'">第 '+n+ ' 篇文章</option>');
											jQuery('#ad_article_pos').get(0).value = n;
											return true;
										}
									}
									function ad_show_pagepos() {
										if (jQuery("#ad_type").get(0).value != 'autocontent') {
											jQuery("#ad_page_pos_span").hide();
											return;
										}
										var v = jQuery("#ad_article_pos").get(0).value;
										if (v == 1) {
											jQuery("#ad_page_pos_span").show();
										} else {
											jQuery("#ad_page_pos_span").hide();
										}
									}
								</script>
								<select id="ad_article_pos" name="ad_article_pos" onchange="ad_show_pagepos();">
									<?php
										$hasit = false;
										for ($___i = 1;$___i<=5;$___i++) {
											echo sprintf('<option value="%d"%s>第 %d 篇文章</option>',$___i,($adv->ad_article_pos == $___i)?" selected":"",$___i);
											if (!$hasit && $adv->ad_article_pos == $___i) $hasit = true;
										}
										if (!$hasit)
											echo sprintf('<option value="%d"%s>第 %d 篇文章</option>',$adv->ad_article_pos," selected",$adv->ad_article_pos);
									?>
									<option id="ad_article_pos_lastopt" onclick="ad_apos_add()">第 N 篇文章</option>
								</select></span>
								<select id="ad_position" name="ad_position" onchange="onChange_ad_position()">
								<option value="top"<?php if ($adv->ad_position=='top') echo " selected";?>>文章顶部</option>
								<option value="bottom"<?php if ($adv->ad_position=='bottom') echo " selected";?>>文章底部</option>
								<option value="secondpara"<?php if ($adv->ad_position=='secondpara') echo " selected";?>>第二段前</option>
								<option value="manualfloat"<?php if ($adv->ad_position=='manualfloat') echo " selected";?>>手动嵌入</option>
								<option value="floatleft"<?php if ($adv->ad_position=='floatleft') echo " selected";?>>嵌入左侧</option>
								<option value="floatright"<?php if ($adv->ad_position=='floatright') echo " selected";?>>嵌入右侧</option>
								<option value="manual"<?php if ($adv->ad_position=='manual') echo " selected";?>>自定义格式</option>
								</select>
								<span id="ad_page_pos_span" style="display:none"><select name="ad_page_pos">
									<option value="1"<?php if ($adv->ad_page_pos == 1) echo " selected";?>>只显示于首页、汇整页面等多篇文章的页面</option>
									<option value="2"<?php if ($adv->ad_page_pos == 2) echo " selected";?>>只显示于单篇文章页面</option>
									<option value="3"<?php if ($adv->ad_page_pos == 3) echo " selected";?>>所有页面均显示</option>
								</select></span>
								<script type="text/javascript">ad_show_pagepos();</script>
							</td>
						</tr>
						<tr id="ad_detail_manualformat">
							<th valign="top">自定义格式</th>
							<td><textarea name="ad_manualformat" cols="80" rows="5"><?php echo $adv->ad_manualformat;?></textarea>
								<div><strong>注：</strong>%code% 将被自动替换为<?php if (!$alimama_deluxe->legency_mode) { ?>
								Alimama 广告<?php } else { ?>下面指定的<?php } ?>代码，请不要忘记在您的代码中添加 %code% 标志。</div>
							</td>
						</tr>
						
					</table></td>
				</tr>
<?php if ($alimama_deluxe->legency_mode) { ?>
				<tr>
					<th valign="top">嵌入内容</th>
					<td><textarea cols="80" rows="5" name="ad_alimama_deluxe_js_code"><?php echo $adv->ad_jscode;?></textarea>
						<p>请将您需要显示的广告代码粘贴于此处。(如果您使用手动格式的话，此处内容会替换掉 %code%)</p>
						<input type="hidden" name="alimama_deluxe_color_scheme_name" value="nono" />
						<input type="hidden" name="alimama_deluxe_color_scheme_detail" value='nono' />
						<input type="hidden" name="ad_alimama_pid" value="mm_nosetting_nosetting" />
					</td>
				</tr>
<?php } ?>
				<tr>
					<th>激活</th>
					<td><input type="radio" name="ad_enable" value="enable"<?php if ($adv->ad_enable=='enable') echo " checked";?> />激活&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="ad_enable" value="disable"<?php if ($adv->ad_enable=='disable') echo " checked";?> />禁用</td>
				</tr>
			</table>
<?php if (!$alimama_deluxe->legency_mode) { ?>
<div id="ad_format_settings" style="display:none">
			<h2>广告格式设定</h2>
<div style="margin:10px;padding:10px;border: 1px solid #CCCCCC">
	
	<input type="hidden" name="alimama_deluxe_color_scheme_name" value="<?php echo $adv->ad_style[0];?>" />
	<input type="hidden" name="alimama_deluxe_color_scheme_detail" value='<?php echo stripslashes($adv->ad_style[1]);?>' />
	<div id="alimama-deluxe-adpreview"></div>
	<div id="alimama-deluxe-adcontrol"></div>
	<script type="text/javascript" src="<?php bloginfo("home");?>/wp-content/plugins/alimama-deluxe/alimama-deluxe.js"></script>
	<script type="text/javascript">
		alimama_deluxe_pluginurl = "<?php echo $alimama_deluxe->pluginurl?>";
		start_alimama_deluxe_preview("#alimama-deluxe-adpreview","#alimama-deluxe-adcontrol","mm_memberid_siteid_adzoneid","12","2");
		function change_alimama_ad_show() {
			var pid = jQuery("#ad_alimama_pid").get(0).value;
			if (pid == "-" || pid.length<10) {
				jQuery("#ad_format_settings").hide();
				jQuery("input[@type='submit']").disabled = true;
			} else {
					jQuery("#alimama-pid").get(0).value = pid;
					var this_ad;
					for (i=0;i<adzones.length;i++) {
						if (adzones[i].pid == pid) {
							this_ad = adzones[i];
							break;
						}
					}
					jQuery('#ad_size_code').get(0).value = this_ad.sizecode;
					s = ad_size_type(this_ad.sizecode);
					jQuery('#ad_size_width').get(0).value = s.width;
					jQuery('#ad_size_height').get(0).value = s.height;
				jQuery("#ad_format_settings").show();
					ad_gen_code();
				jQuery("input[@type='submit']").disabled = false;
			}
		}
		jQuery('document').ready(function(){
			change_alimama_ad_show();
		});
	</script>
<?php } ?>
</div>
</div>
			
			<p class="submit">
			<?php if ($action == 'add') { ?>
				<input type="submit" name="alimama_deluxe_add_item" value="添加新广告策略" />
			<?php } else { ?>
				<input type="hidden" name="ad_ID" value="<?php echo $adv->ID;?>" />
				<input type="submit" name="alimama_deluxe_edit_item" value="更新广告策略" />
			<?php } ?>
			</p>
			</form>
			<?php
			break;
		case 'manage':
		default:
		?>
			<h2>广告策略管理<a class="helplink" href="http://alimama-deluxe.wordpresscn.com/category/manual/strategy/" target="_blank">[?]</a></h2>
			<style type="text/css">
				.disabled {background-color: #fff0f0;}
				.disabled-alternate {background-color: #e8dada;}
				a.enable-button:hover {background-color:green;color:white;}
			</style>
			<table id="ad_strategies" class="widefat">
				<thead>
				<tr>
					<th scope="col" id="ad_stg_id" width="40px" style="text-align:center">ID</th>
					<th scope="col" id="ad_stg_name" width="200px">名称</th>
					<th scope="col" id="ad_stg_code" width="300px" style="display:none">代码</th>
					<th scope="col" id="ad_stg_action">行为描述</th>
					<th scope="col" id="ad_stg_ope" colspan="<?php echo ($alimama_deluxe->advance_mode)?"4":"3";?>" style="text-align:center" width="180px">相关操作</th>
				</tr>
				</thead>
				<tbody id="ad_strategies_list">
				<?php
					$rows = $alimama_deluxe->ad_get_strategies();
					if (!$rows) {
				?>
					<tr><td colspan="6">尚无任何广告策略，请创建一些。</td></tr>
				<?php } else {
						foreach ($rows as $row) {
							$class = (strpos($class,'alternate') === false) ? 'alternate':'';
							if ($row->ad_enable == 'disable') {
								$class = ($class == 'alternate')?"disabled-alternate":"disabled";
							}
							?>
							<tr id="alimama_ad_<?php echo $row->ID;?>" class="<?php echo $class; ?>">
								<th style="text-align:center"><?php echo $row->ID;?></th>
								<td><?php echo $row->ad_name;?></td>
								<td style="display:none"><em><?php echo str_replace(array("<",">"),array("&lt;","&gt;"),gen_ad_code($row->ad_code));?></em></td>
								<td><?php echo alimama_deluxe_format_strategy($row);?></td>
								<td><a href="admin.php?page=alimama-deluxe/alimama-deluxe-strategy-manage.php&a=<?php echo $row->ad_enable == 'enable'?'disable':'enable';?>&ad_id=<?php echo $row->ID;?>" class="<?php echo $row->ad_enable == 'enable'?'delete':'edit enable-button';?>"><?php echo $row->ad_enable == 'enable'?'停用':'启用';?></a></td>
								<?php if ($alimama_deluxe->advance_mode) { 
									list($null,$null,$null,$__my_use_zonead) = explode("_",$row->ad_alimama_pid);
								?>
								<td><a href="admin.php?page=alimama-deluxe/alimama-deluxe-aliad.php&a=view&id=<?php echo $__my_use_zonead;?>" class="view">统计</a></td>
								<?php } ?>
								<td><a href="admin.php?page=alimama-deluxe/alimama-deluxe-strategy-manage.php&a=edit&ad_id=<?php echo $row->ID;?>" class="edit">编辑</a></td>
								<td><a href="admin.php?page=alimama-deluxe/alimama-deluxe-strategy-manage.php&a=delete&ad_id=<?php echo $row->ID;?>" onclick="return confirm('删除操作时不可恢复的，您确定要删除广告策略“<?php echo $row->ad_name;?>”吗？');" class="delete">删除</a></td>
							</tr>
							<?php
						}
						$class = ('alternate' == $class) ? '' : 'alternate';
			?>
				<?php
					}
				?>
				<tr class="<?php echo $class; ?>"><td colspan="6"><a href="admin.php?page=alimama-deluxe/alimama-deluxe-strategy-manage.php&a=add" class="edit">添加新策略</a></a>
				</tbody>
				<?php $r = $alimama_deluxe->get_all_filters();
				//var_dump($r);
				//var_dump($alimama_deluxe->all_ad_codes);
				?>
			</table>
		<?php
	}
?>
</div>
